<template>
    <view class="content">
        <view class="text-area">
            <text class="title">{{ title }}</text>
        </view>
        <view class="text-area">
            <text class="title">{{ getTest(test) }}</text>
        </view>
        <view class="text-area">
            <text class="title" v-for="(item,index) in list" :key="index">{{ item }}</text>
        </view>
    </view>
</template>

<script>
import { format, randomNum, arrScrambling, flatten, sample } from '@/utils/utils.js'
export default {
    data() {
        return {
            title: '我的',
            arr: [1, 2, 1, 3, 5, 4, 6, 8, 4],
            arr1: [5, [2, 2], [6, 8]],
            test: 0
        };
    },
    onLoad() {
        this.getArr()
        console.log("千分",format(-5654565522554.555))
        console.log("生成指定范围随机数", randomNum(1,100))
        console.log("数组乱序", arrScrambling(this.arr))
        console.log("数组扁平化", flatten(this.arr1))
        console.log("数组获取随机数", sample(this.arr))
        console.log('vuex', this.$store.state.name)
        console.log('vuex的getters', this.$store.getters.getTitle)
        console.log('原来的数据', this.$store.state.number)
        this.$store.commit('setNumber', { number: 6666 })
        console.log('vuex的Mutation修改', this.$store.state.number)
        this.getNum()
    },
    methods: {
        getArr() {
            // 数组去重
            let newArr = [...new Set(this.arr)]
            console.log("数组去重",newArr)
        },
        getTest(value) {
            if (value == 0) {
                value = '我是靓仔'
            }
            return value
        },
        async getNum (){
            await this.$store.dispatch('setNum')
            console.log('vuex的Action异步修改', this.$store.state.number)
        }
    },
    computed: {
        list() {
            return [1, 2, 3, 4].filter(item => item !== 2)
        }
    }
};
</script>

<style lang="less">
.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    
    .text-area {
        display: flex;
        justify-content: center;
        
        .title {
            font-size: 36rpx;
            color: #8f8f94;
        }
    }
}
</style>
